import { Meteor } from 'meteor/meteor';
import '/lib/router.js';
import '/lib/collection.js';

Meteor.startup(() => {
    Meteor.methods({
        'Userinfo_op':function (data) {
            var  promise = new Promise(function(resolve, reject) {
                Userinfo.upsert({phone:data.phone},{
                        username:data.username,
                        school:data.school,
                        phone:data.phone,
                        num:data.num,
                        time:data.time
                    },
                    function (err,res) {
                        if(!err){
                            resolve(1)
                        }else {
                            reject(0)
                        }
                })
            });
            return promise.then(function (value) {
                console.log(value)
                return value
            })
        }
    });

    if(Meteor.isServer){
        /*set rest*/
        /*var Api = new Restivus({
            apiPath:'tableData/',
            useDefaultAuth: false,
            prettyJson: false,
            enableEcors:false
        });
        /!*signature API*!/
        Api.addRoute('zhongxin', {authRequired: false}, {
            get: {
                authRequired: false,
                action: function () {
                    return  {
                        statusCode: 404,
                        headers: {
                            'Content-Type': 'application/json',
                            'Access-Control-Allow-Origin': '*',
                        },
                        body: {
                            code:1
                        }
                    }
                }
            },

        });*/
    }
});
